In this notebook I want to show, that the error of the median filter depends on the window length of the filter and wave number of the sine wave.
In [1]:
import numpy as np
import matplotlib.pyplot as plt
import sys
# Add a new path with needed .py files.
sys.path.insert(0, 'C:\Users\Dominik\Documents\GitRep\kt-2015-DSPHandsOn\MedianFilter\Python')
import functions
import gitInformation
In [2]:
%matplotlib inline
In [3]:
gitInformation.printInformation()
In [4]:
fig = plt.figure()
for y in range (0, 40):
if y % 2 == 1:
functions.ErrorPlotWindow(5, y)
plt.savefig('WLError.png')
As you can see, the error is higher when the window is bigger.
The error rate is the mean of the absolute of the red line. The red line is the difference between the sine wave and the median filtered wave. With a bigger window the difference between median filtered wave and sine wave gets bigger. Thus we can say that the error depends on the size of the window.
In [5]:
plt.figure(figsize=(30,20))
for x in range(1, 5):
for y in range(1, 6):
# Creates different subplots in one figure, with x and y.
# the window length is calculate.
plt.subplot(5, 5, x + (y-1)*4)
windowLength = ((x-1)*2 + (y-1)*8)*8 +1
functions.medianSinPlot(16, windowLength, 16*128,128*5+1,-128*5-1)
plt.suptitle('Median filtered sine waves', fontsize = 48)
plt.xlabel(("Window length (/2 pi) = " + str(windowLength/128.)), fontsize=18)
In [6]:
fig = plt.figure(figsize=(30,20))
for x in range(1, 5):
for y in range(1, 6):
for z in range(0,40):
if z%2 ==1:
plt.subplot(5, 5, x + (y-1)*4)
wavenum = (x-1) + (y-1)*4
functions.ErrorPlotWindow(wavenum, z)
plt.suptitle(' Error of the Median filter with different wave numbers and window lengths',
fontsize = 40)
plt.xlabel(("Wave number = " + str((x-1) + (y-1)*4)), fontsize = 18)
At the beginning you can see the error rises with a higher wave number. But at the end there are some unlikely curves. This is because of the low samples(128).
In [7]:
fig = plt.figure(figsize=(30,20))
for x in range(1, 5):
for y in range(1, 6):
for z in range(0,160,3):
if z%2 ==1:
plt.subplot(5, 5, x + (y-1)*4)
wavenum = (x-1) + (y-1)*4
functions.ErrorPlotWindow( wavenum, z, 1024 )
plt.suptitle(' Error of the Median filter with different wave numbers and window lengths ',
fontsize = 40)
plt.xlabel(("Wave number = " + str((x-1) + (y-1)*4)), fontsize = 18)
plt.savefig('SumErrorWL')
With more samples we get much smoother and better curves. As already mentioned rises the error with a higher wave number and bigger window. At wave number 11 - 19 we can see that the error gets smaller when the window length is big.